<?php
/**
 * 焦点图管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: FocusModel.class.php v1.0 2014-06-23 17:27:03 $
 */
namespace Admin\Service;
class FocusService extends CommonService{
    
    public function add($data) {
        $FocusModel = $this->getD();
        if(false === ($focus = $FocusModel->create($data))){
            return $this->errorResultReturn($FocusModel->getError());
        }
        
        if(false === $FocusModel->add($focus)){
            return $this->errorResultReturn("系统繁忙！");
        }
        return $this->resultReturn(TRUE);
    }
    
    public function update($data) {
        $FocusModel = $this->getD();
        $FocusModel->preUpdate($data["id"]);
        if(false === ($focus = $FocusModel->create($data))){
            return $this->errorResultReturn($FocusModel->getError());
        }
        
        if(false === $FocusModel->save($focus)){
            return $this->errorResultReturn("系统繁忙！");
        }
        $FocusModel->afterUpdate();
        return $this->resultReturn(TRUE);
    }
    /**
     * 删除焦点图
     * @param type $id
     * @return type
     */
    public function delete($id) {
        $where = array("id" => $id);
        return $this->getD()->where($where)->delete();
    }
    /**
     * 检查焦点图是否可用
     * @param  array $focus 需要检查的语言
     * @param  int   $id    需要更新语言的id
     * @return array
     */
    public function checkFocus($focus, $id) {
        $FocusModel = $this->getD();
        $focus = array_map('trim', $focus);

        if ($FocusModel->isValid($focus, $id)) {
            return $this->resultReturn(true);
        }
        return $this->errorResultReturn($FocusModel->getError());
    }
    
    /**
     * 根据ID获取焦点图详情
     * @param type $id
     * @return type
     */
    public function getById($id) {
        return $this->getD()->relation(true)->getById($id);
    }
    
    /**
     * 获取焦点图详细
     * @param type $nid
     * @return type
     */
    public function getByNid($nid) {
        return $this->getD()->relation(true)->getByNid($nid);
    }
    
    /**
     * 获取所有
     * @param array $where
     * @param type $field
     * @return type
     */
    public function getAll(array $where, $field = "*") {
        return $this->getM()->field($field)->where($where)->select();
    }
    protected function getModelName() {
        return "Focus";
    }
}
